<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns:yui="http://yuilibrary.com/rdf/1.0/yui.rdf#">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<title>API: Base   svg.js  (YUI Library)</title>

	<link rel="stylesheet" type="text/css" href="assets/reset-fonts-grids-min.css?stamp=1314919672.96" />
	<link rel="stylesheet" type="text/css" href="assets/api.css?stamp=1314919672.96" />

    <script type="text/javascript" src="assets/api-js?stamp=1314919672.96"></script>
    <script type="text/javascript" src="assets/ac-js?stamp=1314919672.96"></script>
</head>

<body id="yahoo-com">

<div id="doc3" class="yui-t2">
	<div id="hd">
        <h1><a href="http://developer.yahoo.com/yui/" title="g-javascript-lib">g-javascript-lib</a></h1>
        <h3>Base&nbsp; <span class="subtitle">1.0.0</span></h3>
        <a href="./index.html" title="g-javascript-lib">g-javascript-lib</a> 
            &gt; <a href="./module_base.html" title="Base">Base</a>
                
                 &gt; svg.js (source view) 
        <form onsubmit="return false">
            <div id="propertysearch">
                Search: <input autocomplete="off" id="searchinput" />
                <div id="searchresults">
                    &nbsp;
                </div>
            </div>
        </form>
	</div>

	<div id="bd">
		<div id="yui-main">
			<div class="yui-b">
            <form action="#" name="yui-classopts-form" method="get" id="yui-classopts-form">
                <fieldset>
                    <legend>Filters</legend>
                <span class="classopts"><input type="checkbox" name="show_private" id="show_private" /> <label for="show_private">Show Private</label></span>
                <span class="classopts"><input type="checkbox" name="show_protected" id="show_protected" /> <label for="show_protected">Show Protected</label></span>
                <span class="classopts"><input type="checkbox" name="show_deprecated" id="show_deprecated" /> <label for="show_deprecated">Show Deprecated</label></span>
                </fieldset>
            </form>

                    <div id="srcout">
                        <style>
                            #doc3 .classopts { display:none; }
                        </style>
<div class="highlight"><pre><span class="p">(</span><span class="kd">function</span><span class="p">(){</span>
	<span class="nx">SVG_NS</span> <span class="o">=</span> <span class="s2">&quot;http://www.w3.org/2000/svg&quot;</span><span class="p">;</span>

	<span class="cm">/**</span>
<span class="cm">	 * A drawing board in SVG.</span>
<span class="cm">	 * @namespace SVG</span>
<span class="cm">	 * @class Board</span>
<span class="cm">	 */</span>
	<span class="kd">var</span> <span class="nx">SVGBoard</span> <span class="o">=</span> <span class="nx">G</span><span class="p">.</span><span class="nx">GClass</span><span class="p">(</span><span class="s1">&#39;SVG&#39;</span><span class="p">,</span> <span class="s1">&#39;Board&#39;</span><span class="p">,</span> <span class="nx">G</span><span class="p">.</span><span class="nx">Base</span><span class="p">.</span><span class="nx">EventListener</span><span class="p">);</span>
	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__init</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">bw</span><span class="p">,</span> <span class="nx">bh</span><span class="p">,</span> <span class="nx">u</span><span class="p">)</span> <span class="p">{</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">__Base__EventListener__init</span><span class="p">();</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_showGrid</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_snapGrid</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_grid</span> <span class="o">=</span> <span class="mi">10</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">unit</span> <span class="o">=</span> <span class="nx">u</span> <span class="o">||</span> <span class="s1">&#39;mil&#39;</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_svg</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_scale</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_scaleStep</span> <span class="o">=</span> <span class="mf">0.2</span><span class="p">;</span>

		<span class="k">this</span><span class="p">.</span><span class="nx">_shapes</span> <span class="o">=</span> <span class="p">[];</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_symbles</span> <span class="o">=</span> <span class="p">[];</span>

		<span class="c1">// Window size</span>
		<span class="c1">//this.w = w || &#39;100%&#39;;	</span>
		<span class="c1">//this.h = h || &#39;100%&#39;;</span>

		<span class="c1">// Board Size</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">boardW</span> <span class="o">=</span> <span class="nx">bw</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">boardH</span> <span class="o">=</span> <span class="nx">bh</span><span class="p">;</span>

		<span class="c1">// 10mil/px</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">w</span> <span class="o">=</span> <span class="s2">&quot;100%&quot;</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">h</span> <span class="o">=</span> <span class="s2">&quot;100%&quot;</span><span class="p">;</span>
		

		<span class="k">this</span><span class="p">.</span><span class="nx">drawMode</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>

		<span class="k">this</span><span class="p">.</span><span class="nx">undoReduStack</span> <span class="o">=</span> <span class="p">[];</span>
	<span class="p">}</span>

	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">render</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">container</span><span class="p">)</span> <span class="p">{</span>
		<span class="kd">var</span> <span class="nx">svg</span><span class="o">=</span><span class="nb">document</span><span class="p">.</span><span class="nx">createElementNS</span><span class="p">(</span><span class="nx">SVG_NS</span><span class="p">,</span><span class="s1">&#39;svg&#39;</span><span class="p">);</span> 
		<span class="nx">svg</span><span class="p">.</span><span class="nx">setAttribute</span><span class="p">(</span><span class="s2">&quot;width&quot;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">w</span><span class="p">);</span>
		<span class="nx">svg</span><span class="p">.</span><span class="nx">setAttribute</span><span class="p">(</span><span class="s2">&quot;height&quot;</span><span class="p">,</span><span class="k">this</span><span class="p">.</span><span class="nx">h</span><span class="p">);</span>
		<span class="nx">container</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">svg</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_svg</span> <span class="o">=</span> <span class="nx">G</span><span class="p">(</span><span class="nx">svg</span><span class="p">);</span>

		<span class="k">this</span><span class="p">.</span><span class="nx">draw_view_board</span><span class="p">();</span>

		<span class="kd">var</span> <span class="nx">g</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_create_element</span><span class="p">(</span><span class="s1">&#39;g&#39;</span><span class="p">,</span> <span class="p">{</span> <span class="nx">width</span><span class="o">:</span> <span class="s1">&#39;100%&#39;</span><span class="p">,</span> <span class="nx">height</span><span class="o">:</span><span class="s1">&#39;100%&#39;</span><span class="p">,</span> <span class="nx">id</span><span class="o">:</span> <span class="s1">&#39;drawbox&#39;</span><span class="p">});</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_svg</span><span class="p">.</span><span class="nx">em</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">g</span><span class="p">);</span>

		<span class="k">this</span><span class="p">.</span><span class="nx">_drawBox</span> <span class="o">=</span> <span class="nx">G</span><span class="p">(</span><span class="nx">g</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_svg</span><span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="s2">&quot;onresize&quot;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">_on_resize</span><span class="p">,</span> <span class="k">this</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_svg</span><span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="s2">&quot;onmousedown&quot;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">_on_mouse_down</span><span class="p">,</span> <span class="k">this</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_svg</span><span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="s2">&quot;onmouseup&quot;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">_on_mouse_up</span><span class="p">,</span> <span class="k">this</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_svg</span><span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="s2">&quot;onmousemove&quot;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">_on_mouse_move</span><span class="p">,</span> <span class="k">this</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_svg</span><span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="s2">&quot;onclick&quot;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">_on_click</span><span class="p">,</span> <span class="k">this</span><span class="p">);</span>
	<span class="p">}</span>

	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_on_resize</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
		<span class="kd">var</span> <span class="nx">w</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_svg</span><span class="p">.</span><span class="nx">em</span><span class="p">.</span><span class="nx">clientWidth</span><span class="p">;</span>
		<span class="kd">var</span> <span class="nx">h</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_svg</span><span class="p">.</span><span class="nx">em</span><span class="p">.</span><span class="nx">clientHeight</span><span class="p">;</span>

		<span class="kd">var</span> <span class="nx">vw</span> <span class="o">=</span> <span class="p">(</span><span class="nx">w</span> <span class="o">/</span> <span class="k">this</span><span class="p">.</span><span class="nx">_scale</span><span class="p">);</span>
		<span class="kd">var</span> <span class="nx">vh</span> <span class="o">=</span> <span class="p">(</span><span class="nx">h</span> <span class="o">/</span> <span class="k">this</span><span class="p">.</span><span class="nx">_scale</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_viewW</span> <span class="o">=</span> <span class="nx">vw</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_viewH</span> <span class="o">=</span> <span class="nx">vh</span><span class="p">;</span>

		<span class="k">this</span><span class="p">.</span><span class="nx">_svg</span><span class="p">.</span><span class="nx">_emViewBoard</span><span class="p">.</span><span class="nx">setAttribute</span><span class="p">(</span><span class="s1">&#39;viewBox&#39;</span><span class="p">,</span> <span class="s1">&#39;0 0 w h&#39;</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_svg</span><span class="p">.</span><span class="nx">em</span><span class="p">.</span><span class="nx">setAttribute</span><span class="p">(</span><span class="s1">&#39;viewBox&#39;</span><span class="p">,</span> <span class="s1">&#39;0 0 &#39;</span> <span class="o">+</span> <span class="nx">vw</span> <span class="o">+</span> <span class="s1">&#39; &#39;</span> <span class="o">+</span> <span class="nx">vh</span><span class="p">);</span>
	<span class="p">}</span>

	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">get_width</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
		<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">boardW</span><span class="p">;</span>
	<span class="p">}</span>
	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">get_height</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
		<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">boardH</span><span class="p">;</span>
	<span class="p">}</span>

	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">draw_view_board</span><span class="o">=</span> <span class="kd">function</span><span class="p">()</span> 
	<span class="p">{</span>
		<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">_svg</span><span class="p">)</span>	<span class="k">return</span><span class="p">;</span>

		<span class="kd">var</span> <span class="nx">g</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_create_element</span><span class="p">(</span><span class="s1">&#39;g&#39;</span><span class="p">,</span> <span class="p">{</span> <span class="nx">width</span><span class="o">:</span> <span class="s1">&#39;100%&#39;</span><span class="p">,</span> <span class="nx">height</span><span class="o">:</span><span class="s1">&#39;100%&#39;</span><span class="p">,</span> <span class="nx">id</span><span class="o">:</span> <span class="s1">&#39;viewboard&#39;</span><span class="p">});</span>
		<span class="kd">var</span> <span class="nx">b</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_create_element</span><span class="p">(</span><span class="s1">&#39;rect&#39;</span><span class="p">,</span> <span class="p">{</span> <span class="nx">width</span><span class="o">:</span> <span class="s1">&#39;100%&#39;</span><span class="p">,</span> <span class="nx">height</span><span class="o">:</span><span class="s1">&#39;100%&#39;</span><span class="p">});</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_emGridBoard</span> <span class="o">=</span> <span class="nx">g</span><span class="p">;</span>
		<span class="nx">g</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">b</span><span class="p">);</span>

		<span class="c1">// Draw Grid</span>
		<span class="kd">var</span> <span class="nx">w</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">get_width</span><span class="p">();</span>
		<span class="kd">var</span> <span class="nx">h</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">get_height</span><span class="p">();</span>
		<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_grid</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">h</span><span class="p">;</span> <span class="nx">i</span><span class="o">+=</span><span class="k">this</span><span class="p">.</span><span class="nx">_grid</span><span class="p">)</span> <span class="p">{</span>
			<span class="kd">var</span> <span class="nx">l</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_create_element</span><span class="p">(</span><span class="s1">&#39;line&#39;</span><span class="p">,</span> <span class="p">{</span><span class="nx">x1</span><span class="o">:</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">y1</span><span class="o">:</span><span class="nx">i</span><span class="p">,</span> <span class="nx">x2</span><span class="o">:</span><span class="s1">&#39;100%&#39;</span><span class="p">,</span> <span class="nx">y2</span><span class="o">:</span> <span class="nx">i</span><span class="p">});</span>
			<span class="nx">g</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">l</span><span class="p">);</span>
		<span class="p">}</span>
		<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_grid</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">w</span><span class="p">;</span> <span class="nx">i</span><span class="o">+=</span><span class="k">this</span><span class="p">.</span><span class="nx">_grid</span><span class="p">)</span> <span class="p">{</span>
			<span class="kd">var</span> <span class="nx">l</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_create_element</span><span class="p">(</span><span class="s1">&#39;line&#39;</span><span class="p">,</span> <span class="p">{</span><span class="nx">x1</span><span class="o">:</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">y1</span><span class="o">:</span><span class="mi">0</span><span class="p">,</span> <span class="nx">x2</span><span class="o">:</span><span class="nx">i</span><span class="p">,</span> <span class="nx">y2</span><span class="o">:</span> <span class="s1">&#39;100%&#39;</span><span class="p">});</span>
			<span class="nx">g</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">l</span><span class="p">);</span>
		<span class="p">}</span>

		<span class="k">this</span><span class="p">.</span><span class="nx">_svg</span><span class="p">.</span><span class="nx">em</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">g</span><span class="p">);</span>

		<span class="k">this</span><span class="p">.</span><span class="nx">_on_resize</span><span class="p">();</span>

		<span class="c1">// Draw Cursor</span>
		<span class="kd">var</span> <span class="nx">x</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_viewW</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
		<span class="kd">var</span> <span class="nx">y</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_viewH</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">cursorH</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_create_element</span><span class="p">(</span><span class="s1">&#39;line&#39;</span><span class="p">,</span> 
				<span class="p">{</span><span class="nx">x1</span><span class="o">:</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">y1</span><span class="o">:</span> <span class="nx">y</span><span class="p">,</span> <span class="nx">x2</span><span class="o">:</span> <span class="s1">&#39;100%&#39;</span><span class="p">,</span> <span class="nx">y2</span><span class="o">:</span> <span class="nx">y</span><span class="p">,</span> <span class="nx">id</span><span class="o">:</span> <span class="s1">&#39;cursor&#39;</span><span class="p">});</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">cursorV</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_create_element</span><span class="p">(</span><span class="s1">&#39;line&#39;</span><span class="p">,</span> 
				<span class="p">{</span><span class="nx">x1</span><span class="o">:</span> <span class="nx">x</span><span class="p">,</span> <span class="nx">y1</span><span class="o">:</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">x2</span><span class="o">:</span> <span class="nx">x</span><span class="p">,</span> <span class="nx">y2</span><span class="o">:</span> <span class="s1">&#39;100%&#39;</span><span class="p">,</span> <span class="nx">id</span><span class="o">:</span> <span class="s1">&#39;cursor&#39;</span><span class="p">});</span>
		<span class="nx">g</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">cursorH</span><span class="p">);</span>
		<span class="nx">g</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">cursorV</span><span class="p">);</span>

	<span class="p">}</span>

	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_create_element</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">typ</span><span class="p">,</span> <span class="nx">attr</span><span class="p">)</span> <span class="p">{</span>
		<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">_svg</span><span class="p">)</span>	<span class="k">return</span><span class="p">;</span>

		<span class="kd">var</span> <span class="nx">attr</span> <span class="o">=</span> <span class="nx">attr</span> <span class="o">||</span> <span class="kc">null</span><span class="p">;</span>
		<span class="kd">var</span> <span class="nx">o</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElementNS</span><span class="p">(</span><span class="nx">SVG_NS</span><span class="p">,</span> <span class="nx">typ</span><span class="p">);</span>
		<span class="k">if</span> <span class="p">(</span><span class="nx">attr</span><span class="p">)</span> <span class="p">{</span>
			<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">attr</span><span class="p">)</span> <span class="p">{</span>
				<span class="nx">o</span><span class="p">.</span><span class="nx">setAttribute</span><span class="p">(</span><span class="nx">i</span><span class="p">,</span> <span class="nx">attr</span><span class="p">[</span><span class="nx">i</span><span class="p">]);</span>
			<span class="p">}</span>
		<span class="p">}</span>
		<span class="k">return</span> <span class="nx">o</span><span class="p">;</span>
	<span class="p">}</span>

	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">set_grid</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">grid</span><span class="p">)</span> <span class="p">{</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_svg</span><span class="p">.</span><span class="nx">em</span><span class="p">.</span><span class="nx">removeChild</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_emGridBoard</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_grid</span> <span class="o">=</span> <span class="nx">grid</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">draw_view_board</span><span class="p">();</span>
	<span class="p">}</span>

	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_snap_to_grid</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">x</span><span class="p">,</span> <span class="nx">y</span><span class="p">)</span> 
	<span class="p">{</span>
		<span class="kd">var</span> <span class="nx">x</span>  <span class="o">=</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">round</span><span class="p">(</span><span class="nx">x</span> <span class="o">/</span> <span class="k">this</span><span class="p">.</span><span class="nx">_grid</span><span class="p">)</span> <span class="o">*</span> <span class="k">this</span><span class="p">.</span><span class="nx">_grid</span><span class="p">;</span>
		<span class="kd">var</span> <span class="nx">y</span>  <span class="o">=</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">round</span><span class="p">(</span><span class="nx">y</span> <span class="o">/</span> <span class="k">this</span><span class="p">.</span><span class="nx">_grid</span><span class="p">)</span> <span class="o">*</span> <span class="k">this</span><span class="p">.</span><span class="nx">_grid</span><span class="p">;</span>
		<span class="k">return</span> <span class="p">{</span><span class="nx">x</span><span class="o">:</span> <span class="nx">x</span><span class="p">,</span> <span class="nx">y</span><span class="o">:</span> <span class="nx">y</span><span class="p">};</span>
	<span class="p">}</span>

	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_map_mouse_matrix</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">evt</span><span class="p">)</span>
	<span class="p">{</span>
		<span class="kd">var</span> <span class="nx">x</span> <span class="o">=</span> <span class="nx">evt</span><span class="p">.</span><span class="nx">offsetX</span> <span class="o">/</span> <span class="k">this</span><span class="p">.</span><span class="nx">_scale</span><span class="p">;</span>
		<span class="kd">var</span> <span class="nx">y</span> <span class="o">=</span> <span class="nx">evt</span><span class="p">.</span><span class="nx">offsetY</span> <span class="o">/</span> <span class="k">this</span><span class="p">.</span><span class="nx">_scale</span><span class="p">;</span>

		<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_snap_to_grid</span><span class="p">(</span><span class="nx">x</span><span class="p">,</span> <span class="nx">y</span><span class="p">);</span>
	<span class="p">}</span>

	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">zoom_in</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> 
	<span class="p">{</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">set_scale</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_scale</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">_scaleStep</span><span class="p">);</span>
	<span class="p">}</span>

	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">zoom_out</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> 
	<span class="p">{</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">set_scale</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_scale</span> <span class="o">-</span> <span class="k">this</span><span class="p">.</span><span class="nx">_scaleStep</span><span class="p">);</span>
	<span class="p">}</span>

	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">set_scale</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">scale</span><span class="p">)</span> 
	<span class="p">{</span>
		<span class="k">if</span> <span class="p">(</span><span class="nx">scale</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
			<span class="nx">scale</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
		<span class="p">}</span>
		<span class="k">if</span> <span class="p">(</span><span class="nx">scale</span> <span class="o">!=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_scale</span><span class="p">)</span> <span class="p">{</span>
			<span class="k">this</span><span class="p">.</span><span class="nx">_scale</span> <span class="o">=</span> <span class="nx">scale</span><span class="p">;</span>
			<span class="k">this</span><span class="p">.</span><span class="nx">_on_resize</span><span class="p">();</span>
		<span class="p">}</span>
	<span class="p">}</span>


	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">set_unit</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">unit</span><span class="p">)</span> 
	<span class="p">{</span>
	<span class="p">}</span>

	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">add_shape</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> 
	<span class="p">{</span>
	<span class="p">}</span>

	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">del_shape</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> 
	<span class="p">{</span>
	<span class="p">}</span>
	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">add_symbol</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> 
	<span class="p">{</span>
	<span class="p">}</span>
	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">del_symbol</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> 
	<span class="p">{</span>
	<span class="p">}</span>

	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">move_cursor</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">x</span><span class="p">,</span> <span class="nx">y</span><span class="p">)</span>
	<span class="p">{</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">cursorV</span><span class="p">.</span><span class="nx">setAttribute</span><span class="p">(</span><span class="s1">&#39;x1&#39;</span><span class="p">,</span> <span class="nx">x</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">cursorV</span><span class="p">.</span><span class="nx">setAttribute</span><span class="p">(</span><span class="s1">&#39;x2&#39;</span><span class="p">,</span> <span class="nx">x</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">cursorH</span><span class="p">.</span><span class="nx">setAttribute</span><span class="p">(</span><span class="s1">&#39;y1&#39;</span><span class="p">,</span> <span class="nx">y</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">cursorH</span><span class="p">.</span><span class="nx">setAttribute</span><span class="p">(</span><span class="s1">&#39;y2&#39;</span><span class="p">,</span> <span class="nx">y</span><span class="p">);</span>
	<span class="p">}</span>

	<span class="cm">/*</span>
<span class="cm">	 * Mouse Event handlers</span>
<span class="cm">	 */</span>
	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_on_mouse_down</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">ev</span><span class="p">)</span> <span class="p">{</span>
		<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">drawMode</span><span class="p">)</span>		<span class="k">return</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_map_mouse_matrix</span><span class="p">(</span><span class="nx">ev</span><span class="p">);</span>
		<span class="kd">var</span> <span class="nx">p</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_map_mouse_matrix</span><span class="p">(</span><span class="nx">ev</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">drawMode</span><span class="p">.</span><span class="nx">onmousedown</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">ev</span><span class="p">,</span> <span class="nx">p</span><span class="p">);</span>
	<span class="p">}</span>
	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_on_mouse_move</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">ev</span><span class="p">)</span> 
	<span class="p">{</span>

		<span class="kd">var</span> <span class="nx">p</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_map_mouse_matrix</span><span class="p">(</span><span class="nx">ev</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">move_cursor</span><span class="p">(</span><span class="nx">p</span><span class="p">.</span><span class="nx">x</span><span class="p">,</span> <span class="nx">p</span><span class="p">.</span><span class="nx">y</span><span class="p">);</span>

		<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">drawMode</span><span class="p">)</span>		<span class="k">return</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">drawMode</span><span class="p">.</span><span class="nx">onmousemove</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">ev</span><span class="p">,</span> <span class="nx">p</span><span class="p">);</span>
	<span class="p">}</span>
	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_on_mouse_up</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">ev</span><span class="p">)</span> <span class="p">{</span>
		<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">drawMode</span><span class="p">)</span>		<span class="k">return</span><span class="p">;</span>
		<span class="kd">var</span> <span class="nx">p</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_map_mouse_matrix</span><span class="p">(</span><span class="nx">ev</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">drawMode</span><span class="p">.</span><span class="nx">onmouseup</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">ev</span><span class="p">,</span> <span class="nx">p</span><span class="p">);</span>
	<span class="p">}</span>
	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_on_click</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">ev</span><span class="p">)</span> 
	<span class="p">{</span>
		<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">drawMode</span><span class="p">)</span>		<span class="k">return</span><span class="p">;</span>

		<span class="kd">var</span> <span class="nx">p</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_map_mouse_matrix</span><span class="p">(</span><span class="nx">ev</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">move_cursor</span><span class="p">(</span><span class="nx">p</span><span class="p">.</span><span class="nx">x</span><span class="p">,</span> <span class="nx">p</span><span class="p">.</span><span class="nx">y</span><span class="p">);</span>

		<span class="kd">var</span> <span class="nx">p</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_map_mouse_matrix</span><span class="p">(</span><span class="nx">ev</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">drawMode</span><span class="p">.</span><span class="nx">onclick</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">ev</span><span class="p">,</span> <span class="nx">p</span><span class="p">);</span>
	<span class="p">}</span>


	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">draw_line</span><span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">drawMode</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_DrawMode</span><span class="p">[</span><span class="s1">&#39;lineclick&#39;</span><span class="p">];</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">drawMode</span><span class="p">.</span><span class="nx">init</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">);</span>
	<span class="p">}</span>

	<span class="nx">SVGBoard</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">draw_select_mode</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">drawMode</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
	<span class="p">}</span>


	<span class="nx">G</span><span class="p">.</span><span class="nx">DOM</span><span class="p">.</span><span class="nx">Element</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">SVGBoard</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">w</span><span class="p">,</span> <span class="nx">h</span><span class="p">)</span> <span class="p">{</span>
		<span class="kd">var</span> <span class="nx">board</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">SVGBoard</span><span class="p">(</span><span class="nx">w</span><span class="p">,</span> <span class="nx">h</span><span class="p">);</span>
		<span class="nx">board</span><span class="p">.</span><span class="nx">render</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">em</span><span class="p">);</span>
		<span class="k">return</span> <span class="nx">board</span><span class="p">;</span>
	<span class="p">}</span>


	<span class="cm">/**</span>
<span class="cm">	 * @namespace SVG</span>
<span class="cm">	 * @class Shape</span>
<span class="cm">	 */</span>
	<span class="nx">Shape</span> <span class="o">=</span> <span class="nx">G</span><span class="p">.</span><span class="nx">GClass</span><span class="p">(</span><span class="s1">&#39;SVG&#39;</span><span class="p">,</span> <span class="s1">&#39;Shape&#39;</span><span class="p">,</span> <span class="nx">G</span><span class="p">.</span><span class="nx">Base</span><span class="p">.</span><span class="nx">EventListener</span><span class="p">);</span>
	<span class="nx">Shape</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__init</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">board</span><span class="p">,</span> <span class="nx">x</span><span class="p">,</span> <span class="nx">y</span><span class="p">)</span> <span class="p">{</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">x</span> <span class="o">=</span> <span class="nx">x</span> <span class="o">||</span> <span class="mi">0</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">y</span> <span class="o">=</span> <span class="nx">y</span> <span class="o">||</span> <span class="mi">0</span><span class="p">;</span>
	<span class="p">}</span>

 <span class="p">})();</span>
</pre></div>
                    </div>
			</div>
		</div>
		<div class="yui-b">
            <div class="nav">

                    <div id="moduleList" class="module">
                        <h4>Modules</h4>
                        <ul class="content">
                                <li class="selected"><a href="module_Base.html" title="Base">Base</a></li>
                                <li class=""><a href="module_test.html" title="test">test</a></li>
                                <li class=""><a href="module_utils.html" title="utils">utils</a></li>
                                <li class=""><a href="module_widget.html" title="widget">widget</a></li>
                        </ul>
                    </div>

                    <div id="classList" class="module">
                        <h4>Classes</h4>
                        <ul class="content">
                                <li class=""><a href="DOM.EventListener.html" title="DOM.EventListener">DOM.EventListener</a></li>
                                <li class=""><a href="DOM.G.html" title="DOM.G">DOM.G</a></li>
                                <li class=""><a href="SVG.Board.html" title="SVG.Board">SVG.Board</a></li>
                                <li class=""><a href="SVG.Shape.html" title="SVG.Shape">SVG.Shape</a></li>
                        </ul>
                    </div>

                    <div id="fileList" class="module">
                        <h4>Files</h4>
                        <ul class="content">        
                                <li class=""><a href="dgrid.js.html" title="dgrid.js">dgrid.js</a></li>
                                <li class=""><a href="drawmode.js.html" title="drawmode.js">drawmode.js</a></li>
                                <li class=""><a href="keycmd.js.html" title="keycmd.js">keycmd.js</a></li>
                                <li class=""><a href="scrollbar.js.html" title="scrollbar.js">scrollbar.js</a></li>
                                <li class="selected"><a href="svg.js.html" title="svg.js">svg.js</a></li>
                        </ul>
                    </div>





            </div>
		</div>
	</div>
	<div id="ft">
        <hr />
        Copyright &copy; 2011 Yahoo! Inc. All rights reserved.
	</div>
</div>
<script type="text/javascript">
    ALL_YUI_PROPS = [{"url": "DOM.EventListener.html#method_bind", "access": "", "host": "DOM.EventListener", "type": "method", "name": "bind"}, {"url": "DOM.EventListener.html#method_fire", "access": "", "host": "DOM.EventListener", "type": "method", "name": "fire"}, {"url": "DOM.G.html#method_GClass", "access": "", "host": "DOM.G", "type": "method", "name": "GClass"}, {"url": "DOM.EventListener.html#method___listen", "access": "", "host": "DOM.EventListener", "type": "method", "name": "__listen"}, {"url": "DOM.G.html#method_Namespace", "access": "", "host": "DOM.G", "type": "method", "name": "Namespace"}, {"url": "DOM.EventListener.html#method_unbind", "access": "", "host": "DOM.EventListener", "type": "method", "name": "unbind"}, {"url": "DOM.EventListener.html#method___unlisten", "access": "", "host": "DOM.EventListener", "type": "method", "name": "__unlisten"}];
</script>
</body>
</html>
